package com.oddfar.campus.business.mapper;

import com.oddfar.campus.business.domain.Czxx;
import com.oddfar.campus.common.core.BaseMapperX;
import com.oddfar.campus.common.core.LambdaQueryWrapperX;
import com.oddfar.campus.common.domain.PageResult;
import com.oddfar.campus.common.domain.entity.SysUserEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

public interface CzxxMapper extends BaseMapperX<Czxx> {

    default PageResult<Czxx> selectPage(Czxx czxx) {

        return selectPage(new LambdaQueryWrapperX<Czxx>()
                .eqIfPresent(Czxx::getUserId, czxx.getUserId())
                .eqIfPresent(Czxx::getPhonenumber, czxx.getPhonenumber())
                .eqIfPresent(Czxx::getEmail, czxx.getEmail())
                .eqIfPresent(Czxx::getClpzh, czxx.getClpzh())
                .orderByAsc(Czxx::getCreateTime)
        );

    }

    default PageResult<Czxx> selectPage(Czxx czxx, Long userId) {

        return selectPage(new LambdaQueryWrapperX<Czxx>()
                .eqIfPresent(Czxx::getUserId, czxx.getUserId())
                .eqIfPresent(Czxx::getPhonenumber, czxx.getPhonenumber())
                .eqIfPresent(Czxx::getEmail, czxx.getEmail())
                .eqIfPresent(Czxx::getClpzh, czxx.getClpzh())
                .orderByAsc(Czxx::getCreateTime)
        );

    }

    @Delete("DELETE FROM dj_czxx WHERE user_id in (#{userid})")
    int deleteCzxx(Long userid); //此处之前是Long[]数组

    default Czxx checkPhoneUnique(String phonenumber) {
        return selectOne(new LambdaQueryWrapperX<Czxx>().eq(Czxx::getPhonenumber, phonenumber));
    }

    @Insert("INSERT INTO oddfar_campus.sys_user (user_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, login_ip, login_date, remark, create_user, create_time, update_user, update_time, del_flag) VALUES (#{userId}, #{userName}, #{nickName}, #{userType, jdbcType=VARCHAR}, #{email, jdbcType=VARCHAR}, #{phonenumber, jdbcType=VARCHAR}, #{sex}, #{avatar, jdbcType=VARCHAR}, #{password}, #{status, jdbcType=VARCHAR}, #{loginIp, jdbcType=VARCHAR}, #{loginDate, jdbcType=TIMESTAMP}, #{remark, jdbcType=VARCHAR}, #{createUser}, #{createTime, jdbcType=TIMESTAMP}, #{updateUser}, #{updateTime, jdbcType=TIMESTAMP}, #{delFlag, jdbcType=BOOLEAN})")
    void tongbuxitongyonghu(com.oddfar.campus.business.domain.Czxx czxx);

    @Insert("INSERT INTO sys_user_role ( user_id, role_id ) VALUES ( #{userId}, 1784387165048909826 )")
    void tongbuquanxian(com.oddfar.campus.business.domain.Czxx czxx);

    @Select("SELECT user_id from oddfar_campus.dj_czxx order by user_id desc LIMIT 1")
    Long chaxunzuidaid();

}